package com.ui.design.main.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.android.arouter.launcher.ARouter;
import com.ui.design.R;
import com.ui.design.main.bean.SelectorBean;

import java.util.List;

/**
 * 选项适配器
 * tangxianfeng
 * 2021.7.21
 */
public class SelectorAdapter extends RecyclerView.Adapter<SelectorAdapter.SViewHolder> {

    private final List<SelectorBean> selectorList;
    private final Context mContext;

    public SelectorAdapter(Context context, List<SelectorBean> selectors){
        this.mContext=context;
        this.selectorList=selectors;
    }
    @NonNull
    @Override
    public SViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new SViewHolder(LayoutInflater.from(mContext).inflate(R.layout.selector_item, parent,false));
    }

    @Override

    public void onBindViewHolder(@NonNull SViewHolder holder, int position) {

        holder.cardname.setText(selectorList.get(position).Selectorname);
        holder.itemView.setOnClickListener(v -> {
            ARouter.getInstance().build(selectorList.get(position).routeName).withString("title",selectorList.get(position).Selectorname).withString("blogurl",selectorList.get(position).blogurl).navigation();
        });
    }

    @Override
    public int getItemCount() {
        return selectorList.size();
    }

    static class SViewHolder extends RecyclerView.ViewHolder{

        private final TextView cardname;
        public SViewHolder(@NonNull View itemView) {
            super(itemView);
            cardname=(TextView) itemView.findViewById(R.id.card_selector_name);
        }

    }
}
